#ifndef _PARM_CFG_H_
#define _PARM_CFG_H_

#define CMD_SET_LOGIN_CONFIG            (99)
#define CMD_LOGIN_CHECK                 (100)
#define CMD_GET_UART_CONFIG             (101)
#define CMD_POST_UART_CONFIG            (102)
#define CMD_GET_NETWORK_INFO            (103)
#define CMD_GET_NETWORK_CONFIG          (104)
#define CMD_POST_NETWORK_CONFIG         (105)
#define CMD_GET_VOUCHER_CONFIG          (106)
#define CMD_POST_VOUCHER_CONFIG         (107)
#define CMD_GET_NTP_SERVER_CONFIG       (108)
#define CMD_POST_NTP_SERVER_CONFIG      (109)
#define CMD_GET_OTA_SERVER_CONFIG       (110)
#define CMD_POST_OTA_SERVER_CONFIG      (111)

typedef enum
{
    UART_RS485 = 0,
    UART_RS232,
}uart_type_e;
typedef enum
{
    DEVICE_MASTER = 0,
    DEVICE_SLAVE,
}modbus_type_e;
typedef enum
{
    BAUD_1200   = 1200,
    BAUD_4800   = 4800,
    BAUD_9600   = 9600,
    BAUD_19200  = 19200,
    BAUD_38400  = 38400,
    BAUD_57600  = 57600,
    BAUD_115200 = 115200,
}uart_baud_e;
typedef enum
{
    DATA_5_BIT  = 5,
    DATA_6_BIT  = 6,
    DATA_7_BIT  = 7,
    DATA_8_BIT  = 8,
}uart_data_bit_e;
typedef enum
{
    NONE = 0,
    EVEN = 1,
    ODD  = 2,
}uart_verify_bit_e;
typedef enum
{
    NOT_CONFIGURED = 0,
    CONFIGURED     = 1,
}net_config_e;

#define LOGIN_NAME_LENGTH           (32)
#define LOGIN_PWD_LENGTH            (32)
typedef struct{
    char user[LOGIN_NAME_LENGTH];
    char pwd[LOGIN_PWD_LENGTH];
}login_data_t;

typedef struct{
    uart_type_e type;
    modbus_type_e mode;
    uart_baud_e baud;
    uart_data_bit_e data_bit;
    double stop_bit;                 /* 0 1.5 2 */
    uart_verify_bit_e verify;
    unsigned int sub_station;       /* 子站点 */
    unsigned int get_cycle;         /* 采集周期 */
    // unsigned int report_cycle;      /* 存储上报周期 */
}uart_config_t;

typedef union {
    struct {
        unsigned char di_1 : 1;
        unsigned char di_2 : 1;
        unsigned char di_3 : 1;
        unsigned char di_4 : 1;
        unsigned char di_5 : 1;
        unsigned char di_6 : 1;
        unsigned char reserved : 2;
    };
    unsigned int val;
} di_info_t;
typedef union {
    struct {
        unsigned char do_1 : 1;
        unsigned char do_2 : 1;
        unsigned char do_3 : 1;
        unsigned char do_4 : 1;
        unsigned char do_5 : 1;
        unsigned char do_6 : 1;
        unsigned char reserved : 2;
    };
    unsigned int val;
} do_info_t;
typedef struct{
    di_info_t di_val;
    do_info_t do_val;
    // unsigned int get_cycle;         /* 采集周期 */
    // unsigned int report_cycle;      /* 存储上报周期 */
}dido_config_t;

#define DEVICE_NAME_LENGTH          (32)
typedef struct{
    char name[DEVICE_NAME_LENGTH];
    net_config_e status;
    unsigned int ip_addr;
    unsigned int ip_mask;
    unsigned int ip_gateway;
    unsigned int ip_dns1;
    unsigned int ip_dns2;
}network_config_t;

#define VOUCHER_LENGTH          (48)
typedef struct{
    unsigned char user_id[VOUCHER_LENGTH];
    unsigned char cert[VOUCHER_LENGTH];
}voucher_config_t;

typedef struct{
    unsigned int server_addr;
    // unsigned int server_port;
}ntp_config_t;

#define OTA_LENGTH              (64)
typedef struct{
    unsigned char device_id[OTA_LENGTH];
    unsigned char products_id[OTA_LENGTH];
    unsigned int server_addr;
    unsigned int server_port;
    unsigned char secureld[OTA_LENGTH];
    unsigned char secureKey[OTA_LENGTH];
}ota_config_t;

typedef enum
{
    STO_FAIL    = -1,
    STO_SUCCESS = 0,
    STO_REQUEST_FAIL,       /* 开辟不了空间，没法处理收到的json数据 */
    STO_PARSE_FAIL,         /* JSON解析失败 */
    STO_ACCOUNT_ERROR,      /* 登录信息错误 */
    STO_NO_DATA,            /* 文件中没有这个数据 */
    STO_NO_MEMONY,          /* 文件中没有内存了 */
    STO_MEM_CPY_FAIL,       /* 内存拷贝失败 */
    STO_BUFFER_TOO_SMALL,   /* 要拷贝的内存大小过小 */
    STO_STORAGE_FAILED,     /* 文件系统存储失败 */
}error_e;

#if 1                       /* 调试开关 */
#define storage_debug(...) \
do { \
    printf("[%s:%d->%s] ",__FILE__, __LINE__, __func__); \
    printf(__VA_ARGS__); \
} while (0)
#else
#define storage_debug(...)
#endif

#endif /* _PARM_CFG_H_ */

